home *** CD-ROM | disk | FTP | other *** search
/ Programming Languages Suite / ProgramD2.iso / Borland / Borland C++ V5.02 / OCFINC.PAK / OCPART.H < prev    next >
C/C++ Source or Header  |  1997-05-06  |  8KB  |  254 lines

  1. //----------------------------------------------------------------------------
  2. // ObjectComponents
  3. // Copyright (c) 1994, 1997 by Borland International, All Rights Reserved
  4. //
  5. // $Revision:   2.13  $
  6. //
  7. // Definition of TOcPart class
  8. //----------------------------------------------------------------------------
  9. #if !defined(OCF_OCPART_H)
  10. #define OCF_OCPART_H
  11.  
  12. #if !defined(OCF_OCBOCOLE_H)
  13. # include <ocf/ocbocole.h>
  14. #endif
  15. #if !defined(OCF_OCOBJECT_H)
  16. # include <ocf/ocobject.h>
  17. #endif
  18. #if !defined(OCF_AUTODEFS_H)
  19. # include <ocf/autodefs.h>
  20. #endif
  21. #if !defined(CLASSLIB_VECTIMP_H)
  22. # include <classlib/vectimp.h>
  23. #endif
  24. #if !defined(WINSYS_GEOMETRY_H)
  25. # include <winsys/geometry.h>
  26. #endif
  27.  
  28. #if defined(BI_NAMESPACE)
  29. namespace OCF {
  30. #endif
  31.  
  32. //
  33. // Classes referenced
  34. //
  35. class _ICLASS TOcStorage;
  36. class _ICLASS TOcDocument;
  37. class TOcVerb;
  38.  
  39. //
  40. // class TOcPart
  41. // ~~~~~ ~~~~~~~
  42. // OC part class represents an embeded or linked part in a document
  43. //
  44. class _ICLASS TOcPart : public TUnknown, protected IBSite2 {
  45.   public:
  46.     TOcPart(TOcDocument& document, int id = 0);
  47.     TOcPart(TOcDocument& document, const char far* name);
  48.     TOcPart(TOcDocument& document, TOcInitInfo far& initInfo, TRect pos,
  49.             int id = 0);
  50.  
  51.     virtual bool Init(TOcInitInfo far* initInfo, TRect pos);
  52.  
  53.     void    Delete();
  54.  
  55.     bool    operator ==(const TOcPart& other) {return ToBool(&other == this);}
  56.  
  57.     // Delegated doc functions from TOcDocument
  58.     //
  59.     IBPart*     GetBPartI()  {return BPartI;}
  60.     TOcStorage* GetStorage() {return Storage;}
  61.     void        SetStorage(IStorage* storage, bool remember = true);
  62.     bool    Save(bool SameAsLoad = true, bool remember = true);
  63.     bool    Load();
  64.     int     Detach();
  65.     void    FinishLoading();
  66.  
  67.     // Position & size information
  68.     //
  69.     TPoint  GetPos() const {return Pos;}
  70.     void    SetPos(const TPoint& pos);
  71.     TSize   GetSize() const;
  72.     void    SetSize(const TSize& size);
  73.     TRect   GetRect() const {return TRect(Pos, Size);}
  74.     void    UpdateRect();
  75.     bool    IsVisible(const TRect& logicalRect) const
  76.               {return ToBool(IsVisible() && logicalRect.Touches(GetRect()));}
  77.  
  78.     // Flag accessor functions
  79.     //
  80.     void    Select(bool select)
  81.               {if (select) Flags |= Selected; else Flags &= ~Selected;}
  82.     bool    IsSelected() const {return ToBool(Flags&Selected);}
  83.     void    SetVisible(bool visible);
  84.     bool    IsVisible() const {return ToBool(Flags&Visible);}
  85.     bool    IsActive() const {return ToBool(Flags&Active);}
  86.     void    SetActive() {Flags |= Active;}
  87.     bool    IsLink() const {return ToBool(Flags&Link);}
  88.  
  89.     // Naming
  90.     //
  91.     TString    GetName() {return Name;}
  92.     void       Rename();
  93.  
  94.     // Pass thru functions to corresponding IBPart
  95.     //
  96.     bool    Save(IStorage* storage, bool sameAsLoad, bool remember);
  97.     bool    Draw(HDC dc, const TRect& pos, const TRect& clip, TOcAspect aspect = asDefault);
  98.     bool    Activate(bool activate);
  99.     bool    Show(bool show) {return HRSucceeded(BPartI->Show(show));}
  100.     bool    Open(bool open) {return HRSucceeded(BPartI->Open(open));}
  101.     HWND    OpenInPlace(HWND hwnd) {return BPartI->OpenInPlace(hwnd);}
  102.     bool    CanOpenInPlace() {return HRSucceeded(BPartI->CanOpenInPlace());}
  103.     bool    Close();
  104.     bool    SetHost(IBContainer far* container)
  105.               {return HRSucceeded(BPartI->SetHost(container));}
  106.  
  107.     bool    EnumVerbs(const TOcVerb&);
  108.     bool    DoVerb(uint);
  109.     LPCOLESTR    GetServerName(TOcPartName partName)
  110.         {return const_cast<LPOLESTR>(BPartI->GetName((TOcPartName)partName));}
  111.     HRESULT QueryServer(const IID far& iid, void far* far* iface);
  112.  
  113.     bool    SetFormatData(TOcFormatInfo far* fmt, HANDLE data, bool release);
  114.  
  115.     // Object reference & lifetime managment
  116.     // For internal OCF use only
  117.     //
  118.     ulong   _IFUNC AddRef() {return GetOuter()->AddRef();}
  119.     ulong   _IFUNC Release() {return GetOuter()->Release();}
  120.     HRESULT _IFUNC QueryInterface(const GUID far& iid, void far*far* iface)
  121.                      {return GetOuter()->QueryInterface(iid, iface);}
  122.  
  123.   protected:
  124.    ~TOcPart();
  125.  
  126.     virtual bool InitObj (TOcInitInfo far* initInfo);
  127.  
  128.     // TUnknown virtual overrides
  129.     //
  130.     HRESULT      QueryObject(const IID far& iid, void far* far* iface);
  131.  
  132.     // IBSite implementation for BOle to use
  133.     //
  134.     HRESULT   _IFUNC SiteShow(BOOL);
  135.     HRESULT   _IFUNC DiscardUndo();
  136.     HRESULT   _IFUNC GetSiteRect(TRect far*, TRect far*);
  137.     HRESULT   _IFUNC SetSiteRect(const TRect far*);
  138.     HRESULT   _IFUNC SetSiteExtent(const TSize far*);
  139.     HRESULT   _IFUNC GetZoom(TOcScaleInfo far* scale);
  140.     void      _IFUNC Invalidate(TOcInvalidate);
  141.     void      _IFUNC OnSetFocus(BOOL set);
  142.     HRESULT   _IFUNC Init(IBDataProvider far*, IBPart far*, LPCOLESTR, BOOL);
  143.     void      _IFUNC Disconnect();
  144.  
  145.     // IBSite2 implementation for BOle to use
  146.     //
  147.     HRESULT   _IFUNC GetParentWindow(HWND FAR*);
  148.  
  149.   protected:
  150.     IUnknown*    BPart;      // Our corresponding helper object & interfaces
  151.     IBPart*      BPartI;
  152.     IBLinkable*  BLPartI;
  153.  
  154.     TOcDocument& OcDocument; // The OC document we are imbeded in
  155.     TOcStorage*  Storage;    // The storage we are in
  156.  
  157.     string       Name;
  158.     TPoint       Pos;
  159.     TSize        Size;
  160.     enum TFlag { Visible=0x01, Selected=0x02, Active=0x04, Link=0x08,
  161.                  Closing=0x10, OcxDefault=0x20, OcxCancel=0x40 };
  162.     uint16       Flags;      // Is this part Selected/Visible/Active/ALink?
  163.  
  164.   friend class TOcPartCollection;
  165. };
  166.  
  167. //
  168. // class TOcPartCollection
  169. // ~~~~~ ~~~~~~~~~~~~~~~~~
  170. // Container of parts with iterator
  171. //
  172. class TOcPartCollection : private TCVectorImp<TOcPart*> {
  173.   private:
  174.     typedef TCVectorImp<TOcPart*> Base;
  175.     friend class TOcPartCollectionIter;
  176.   public:
  177.     TOcPartCollection();
  178.    ~TOcPartCollection();
  179.     void operator delete(void* ptr) {TStandardAllocator::operator delete(ptr);}
  180.  
  181.     void Clear();
  182.     int Add(TOcPart* const& part) {return Base::Add(part);}
  183.     int IsEmpty() const {return Base::IsEmpty();}
  184.     unsigned Find(TOcPart* const& part) const {return Base::Find(part);}
  185.     virtual unsigned Count() const {return Base::Count();}
  186.     int Detach(TOcPart* const& part, int del = 0);
  187.  
  188.     TOcPart*   Locate(TPoint& point);
  189.     bool       SelectAll(bool select = false);
  190. };
  191.  
  192. //
  193. // class TOcPartCollectionIter
  194. // ~~~~~ ~~~~~~~~~~~~~~~~~~~~~
  195. //
  196. class TOcPartCollectionIter : private TCVectorIteratorImp<TOcPart*> {
  197.   private:
  198.     typedef TCVectorIteratorImp<TOcPart*> Base;
  199.   public:
  200.     TOcPartCollectionIter(const TOcPartCollection& c) : Base(c) {}
  201.     operator int() const {return Base::operator int();}
  202.     TOcPart* Current() const {return Base::Current();}
  203.     TOcPart* operator ++(int) {return Base::operator ++(0);}
  204.     TOcPart* operator ++() {return Base::operator ++();}
  205.     void Restart() {Base::Restart();}
  206.     void Restart(unsigned start, unsigned stop) {Base::Restart(start, stop);}
  207. };
  208.  
  209. //
  210. // class TOcVerb
  211. // ~~~~~ ~~~~~~~
  212. class TOcVerb {
  213.   public:
  214.     TOcVerb();
  215.  
  216.   public:
  217.     LPCOLESTR   TypeName;
  218.     LPCOLESTR   VerbName;
  219.     uint        VerbIndex;
  220.     bool        CanDirty;
  221. };
  222.  
  223. //
  224. // class TOcPartChangeInfo
  225. // ~~~~~ ~~~~~~~~~~~~~~~~~
  226. // View/Data change info
  227. //
  228. class TOcPartChangeInfo {
  229.   public:
  230.     TOcPartChangeInfo(TOcPart* part, TOcInvalidate type = invView)
  231.       : Part(part), Type(type) {}
  232.  
  233.     bool     IsDataChange() {return Type & invData;}
  234.     bool     IsViewChange() {return Type & invView;}
  235.  
  236.     void     SetDataChange() {Type |= invData;}
  237.     void     SetViewChange() {Type |= invView;}
  238.  
  239.     TOcPart* GetPart() {return Part;}
  240.     void     SetPart(TOcPart* part) {Part = part;}
  241.  
  242.     int      GetType() {return Type;}
  243.  
  244.   protected:
  245.     int         Type;  // what type of change
  246.     TOcPart*    Part;
  247. };
  248.  
  249. #if defined(BI_NAMESPACE)
  250. } // namespace OCF
  251. #endif
  252.  
  253. #endif  // OCF_OCPART_H
  254.